/* --------------------------------------------------------
 * Copyright (c) aeky , Inc.  All rights reserved.
 * --------------------------------------------------------
 */
package com.aeky.client.view.main;

import com.aeky.client.common.DemoConstants;
import com.aeky.client.common.DemoEvents;
import com.aeky.client.common.Registry;
import com.aeky.client.common.WidgetUtils;
import com.aeky.client.mvc.AppEvent;
import com.aeky.client.mvc.Controller;
import com.aeky.client.mvc.Dispatcher;
import com.aeky.client.mvc.View;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.IconButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.events.ClickHandler;
import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
import com.smartgwt.client.widgets.toolbar.RibbonGroup;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripMenuButton;

/**
 * 
 * @author aeky
 */
public class MainMenuView extends View {

    private HLayout mainMenu;

    public MainMenuView(Controller controller) {
        super(controller);
        mainMenu = Registry.get(DemoConstants.MAIN_MENU);
        this.instanceWidgets();
    }

    private void instanceWidgets() {
        RibbonGroup leftRG = new RibbonGroup();
        leftRG.setAlign(Alignment.CENTER);
        leftRG.setWidth("90%");
        leftRG.setShowTitle(false);
        leftRG.setNumRows(1);
        leftRG.setHeight(30);
        leftRG.setMembersMargin(20);
        leftRG.setLayoutMargin(2);
        // leftRG.addControl(new Label("aaaabbbbcccc"));
        // IButton bt1 = new IButton("aa");
        // leftRG.addControl(bt1);
        IconButton ib1 = new IconButton();
        ib1.setTitle("全部菜单");
        ib1.setIcon("menu/dot3.gif");
        ib1.setHeight(20);
        ib1.setWidth(20);
        leftRG.addControl(ib1);

        IconButton ib2 = new IconButton();
        ib2.setTitle("我的办公桌");
        ib2.setIcon("menu/vote.gif");
        ib2.setHeight(20);
        ib2.setWidth(20);
        ib2.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
            public void onClick(ClickEvent event) {
                AppEvent e = new AppEvent(DemoEvents.IB2, null);
                Dispatcher.forwardEvent(e);
            }
        });
        leftRG.addControl(ib2);

        IconButton ib3 = new IconButton();
        ib3.setTitle("公共事务");
        ib3.setIcon("menu/erp.gif");
        ib3.setHeight(20);
        ib3.setWidth(20);
        ib3.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
            public void onClick(ClickEvent event) {
                AppEvent e = new AppEvent(DemoEvents.IB3, null);
                Dispatcher.forwardEvent(e);
            }
        });
        leftRG.addControl(ib3);

        IconButton ib4 = new IconButton();
        ib4.setTitle("信息交流");
        ib4.setIcon("menu/erp.gif");
        ib4.setHeight(20);
        ib4.setWidth(20);
        leftRG.addControl(ib4);

        IconButton ib5 = new IconButton();
        ib5.setTitle("人力资源");
        ib5.setIcon("menu/hrms.gif");
        ib5.setHeight(20);
        ib5.setWidth(20);
        ib5.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
            public void onClick(ClickEvent event) {
                AppEvent e = new AppEvent(DemoEvents.IB5, null);
                Dispatcher.forwardEvent(e);
            }
        });
        leftRG.addControl(ib5);

        IconButton ib6 = new IconButton();
        ib6.setTitle("销售管理");
        ib6.setIcon("menu/hrms.gif");
        ib6.setHeight(20);
        ib6.setWidth(20);
        leftRG.addControl(ib6);

        IconButton ib7 = new IconButton();
        ib7.setTitle("系统管理");
        ib7.setIcon("menu/hrms.gif");
        ib7.setHeight(20);
        ib7.setWidth(20);
        leftRG.addControl(ib7);

        IconButton ib8 = new IconButton();
        ib8.setTitle("附件程序");
        ib8.setIcon("menu/hrms.gif");
        ib8.setHeight(20);
        ib8.setWidth(20);
        leftRG.addControl(ib8);

        IconButton ib9 = new IconButton();
        ib9.setTitle("常用网址");
        ib9.setIcon("menu/hrms.gif");
        ib9.setHeight(20);
        ib9.setWidth(20);
        leftRG.addControl(ib9);

        leftRG.addControl(WidgetUtils.createPreferenceIconButton());
        leftRG.addControl(WidgetUtils.createOpenHelpDocumentsIconButton());
        leftRG.addControl(WidgetUtils.createLogoutIconButton());
        mainMenu.addMember(leftRG);
    }

    private void instanceWidgets1() {
        ToolStrip toolStrip = new ToolStrip();
        toolStrip.setWidth100();
        ToolStripMenuButton menuButton = new ToolStripMenuButton();
        menuButton.setTitle("aaa");
        MenuItem firstMenuItem = new MenuItem();
        firstMenuItem.setTitle("a");
        firstMenuItem.addClickHandler(new ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
                Layout centerPanel = (Layout) Registry.get("centerPanel");
                centerPanel.addMember(new Label("cccccc"));
            }
        });
        Menu secondMenu = new Menu();
        MenuItem smItem1 = new MenuItem();
        smItem1.setTitle("b1");
        smItem1.addClickHandler(new ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
                Layout centerPanel = (Layout) Registry.get("centerPanel");
                centerPanel.addMember(new Label("aaaabbbb"));
            }
        });
        MenuItem smItem2 = new MenuItem();
        smItem2.setTitle("b2");
        secondMenu.setItems(smItem1, smItem2);

        MenuItem secondMenuItem = new MenuItem();
        secondMenuItem.setTitle("b");
        secondMenuItem.setSubmenu(secondMenu);

        Menu firstMenu = new Menu();
        firstMenu.setTitle("aaa");
        firstMenu.setItems(firstMenuItem, secondMenuItem);
        menuButton.setMenu(firstMenu);
        toolStrip.addMenuButton(menuButton);
        toolStrip.addSeparator();
        mainMenu.addMember(toolStrip);
    }

    /*
     * 
     * @see com.aeky.client.mvc.View#handleEvent(com.aeky.client.mvc.AppEvent)
     */
    @Override
    protected void handleEvent(AppEvent event) {

    }

}
